package com.flin.icesilkworm.examination.bas.populator;
import java.util.Map;
import com.flin.icesilkworm.examination.gen.bas.populator.GeneratedTheExaminationActivityPopulator;
import com.flin.icesilkworm.framework.jdbc.objects.StringAttribute;
import com.flin.icesilkworm.framework.spring.SpringWebUtils;
import com.flin.icesilkworm.framework.jdbc.interceptors.JdbcExampleSupport;
import com.flin.icesilkworm.framework.ui.pojo.standard.StandardUIItemForm;
import com.flin.icesilkworm.examination.bas.constant.ITheBasicExamineeConstant;
import com.flin.icesilkworm.examination.bas.constant.ITheExamineeGroupRelConstant;
import com.flin.icesilkworm.examination.bas.constant.ITheTakeExamConstant;
import com.flin.icesilkworm.examination.bas.exp.TheBasicExamineeExample;
import com.flin.icesilkworm.examination.bas.exp.TheExaminationActivityExample;
import com.flin.icesilkworm.examination.bas.exp.TheExamineeGroupRelExample;

public class TheExaminationActivityPopulator extends GeneratedTheExaminationActivityPopulator  {


	private static TheExaminationActivityPopulator instance = new TheExaminationActivityPopulator();
	

	public static TheExaminationActivityPopulator newInstance() {
		return instance;
	}
	
	//针对每一个查询条件组装方法
	protected void loadExampleByKey(JdbcExampleSupport<?> example, String key,
			StringAttribute fieldAttr, StandardUIItemForm item) {
		
		TheExaminationActivityExample exp = (TheExaminationActivityExample)example;
		
		//
		
	}
	
	
	//条件组装后，需要进行默认判断是否需要扩展
	protected boolean defaultDealExample(TheExaminationActivityExample example,Map<String,String> additions) {
		
		if(additions.containsKey("useTake")){//启动组装应试逻辑
			long userid = SpringWebUtils.getUserId();
//			example.joinTheExamineeDutyExampleByDutyId() 
//				.joinTheBasicExamineeFkDutyId()
//				.andExameeIdEqualTo(userid).or(0);
//				.existsTheBasicExamineeFkDutyId(b, values)
//				.existsTheBasicExamineeFkDutyId(true).or(0)  //;
			example.existsByDutyId().toDutyIdOnTheBasicExaminee(true).or(0)
				.andExameeIdEqualTo(userid);
//			example.existsByDutyId(new TheBasicExamineeExample(),ITheBasicExamineeConstant.DUTY_ID,true).or(0)
//			 	.and("%{0}examee_id = " + userid) 
			example.existsByGroupId().toGroupIdOnTheExamineeGroupRel(true).or(0)
			    .andExamIdEqualTo(userid);
//			example.existsByGroupId(new TheExamineeGroupRelExample(), ITheExamineeGroupRelConstant.GROUP_ID, true).or(0)
//			example.joinTheExamineeGroupExampleByGroupId() 
//				.existsTheExamineeGroupRelFkGroupId(true).or(0)
//				.and("%{0}exam_id = " + userid); 
			
			example.joinTheTakeExamFkActiId().leftJoin() 
				.andExameeIdEqualTo(userid).toLink()
//			    .link("%{0}.examee_id = " + userid)
				.setAttribute(ITheTakeExamConstant.ACTI_FETCH_LIST);
		}
		
//		PopulatorSupport.setDefaultAuthCondition(example);
		
		return super.defaultDealExample(example,additions);//true,直接结束，不做后续的自动条件增加，false:不做直接终止
	}
	
	//遇到别名时组装方式
	public JdbcExampleSupport<?> joinExample(String key, JdbcExampleSupport<?> example,String op,Map<String,String> params) {
		
		return super.joinExample(key,example,op,params);
	}
	
	//针对每个查询条件的自定义条件
	public boolean beforeLoadExample(JdbcExampleSupport<?> example,String key, StringAttribute fieldAttr,
			String op, StandardUIItemForm item,Map<String,String> params) {
		
		return false;
	}
																																																																																																
}